package com.yimils.core.sys.beanUtils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yimils.core.sys.entity.UserEntity;
import com.yimils.core.sys.service.UserRoleService;
import com.yimils.core.sys.service.UserService;
import com.yimils.core.sys.vo.TeamVo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Component
public class TeamVoBeanUtils {

    @Resource(name = "userRoleService")
    private UserRoleService userRoleService;

    @Resource(name = "userService")
    private UserService userService;

    public IPage<TeamVo> deepClone(IPage<UserEntity> src, String level) {
        IPage<TeamVo> pages = new Page<>();
        pages.setCurrent(src.getCurrent());
        pages.setSize(src.getSize());
        pages.setTotal(src.getTotal());
        pages.setPages(src.getPages());
        pages.setRecords(cloneRecords(src.getRecords(), level));
        return pages;
    }


    public List<TeamVo> cloneRecords(List<UserEntity> src, String level) {
        List<TeamVo> recordsVo = new ArrayList<>();
        for (UserEntity userEntity : src) {
            TeamVo vo = new TeamVo();
            vo.setId(userEntity.getId());
            vo.setName(userEntity.getName());
            vo.setNick(userEntity.getNick());
            vo.setMobile(userEntity.getMobile());
            vo.setDevices(5);
            vo.setLevel(level);
            vo.setCreateTime(userEntity.getCreateTime());
            recordsVo.add(vo);
        }
        return recordsVo;
    }

}
